var vm_qushiquerenpici = new Vue({
	el : "#qushiquerenpici",
	data : {
		deptid : $("#deptid").val(),		// 单位ID
		piciid : "",//$("#piciid").val(),		// 专家变动批次ID

		picilist : [],// 专家变动列表custom
		piciid : '',//变动id
		pici : {},//变动表

		//查询用字段
		picimingcheng : '',
		chuangjianshijian : '',

		editflag : '',//1添加 2修改

		pageindex : 1,		// 查询分页初始化页
		pagesize : 10,		// 查询分页初始化页面大小
		pageCount : 0,		// 总页数
		recordCount : 0,	// 总记录数
		targetpage : '', 	// 目标页
	},
	created : function(){
		var _this = this;

		_this.bindPiciList();

	},
	watch : {
		//监控分页情况，刷新列表
		pageindex : function(){
			this.bindPiciList();
		},

		pagesize : function(){
			//
			this.bindPiciList();
		},
	},
	methods : {

		// 根据单位ID查询专家变动申请信息
		bindPiciList : function(){
			var _this = this;

			var pici_layer = layer.open({type:3});
			$.post('/system/qushiquerenpici/list', {
				picimingcheng : _this.picimingcheng,
				kaishishijian : _this.chuangjianshijian,
				// pageindex : _this.pageindex,
				// pagesize : _this.pagesize,
				rdm : Math.random()
			},function(ppData) {
				layer.close(pici_layer);

				if (ppData.code == 0) {
					var data = ppData.rows;
					_this.picilist = data;

					// var pageInfo = data.PageInfo;
					// _this.pageindex = pageInfo.pageIndex;
					// _this.pageCount = pageInfo.pageCount;
					// _this.recordCount = pageInfo.recordCount;
					// _this.targetpage = '';
				}
			},"json");
		},

		bindPici : function(){
			var _this = this;

			var pici_layer = layer.open({type:3});
			$.post('/system/qushiquerenpici/findone', {
				id : _this.piciid,
				rdm : Math.random()
			},function(ppData) {
				layer.close(pici_layer);

				if(ppData != null){

					if(ppData.result == "1"){
						var data = ppData.resultContent;
						_this.pici = data;
						_this.pici.id = _this.piciid;
					}else{
						layer.alert(ppData.message);
					}
				}
			},"json");
		},

		toAdd:function(){
			var _this = this;

			$("#myModalLabel").html("添加人口库核查批次");
			$("#modal-dialog").attr("style", "width:1200px;");
			$("#piciModal").modal();

			this.pici = {};
			this.editflag = 1;
		},

		//添加
		add:function(){
			var _this = this;
			if (_this.checkInputData()) {
				var pici_layer = layer.open({type: 3});
				$.post('/system/qushiquerenpici/add', {
					picimingcheng : _this.pici.picimingcheng,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(pici_layer);
					if (ppData != null) {

						if (ppData.code == "0") {
							layer.open({
								time: 1000,
								btn: [],
								content: "添加成功!",
							});

							_this.refresh();
							$("#piciModal").modal('hide');

						} else {
							layer.alert(ppData.msg);
						}
					}
				}, "json");
			}
		},

		toModify:function(ppPiciId){

			$("#myModalLabel").html("修改人口库核查批次");
			$("#modal-dialog").attr("style","width:1200px;");
			$("#piciModal").modal();

			this.piciid = ppPiciId;

			this.pici = {};
			this.editflag = 2;
			// 绑定变动
			this.bindPici();
		},

		// 修改信息
		modify : function(){
			var _this = this;
			if (_this.checkInputData()) {
				var pici_layer = layer.open({type: 3});
				$.post('/system/qushiquerenpici/edit', {
					id: _this.piciid,
					picimingcheng : _this.pici.picimingcheng,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(pici_layer);
					if (ppData != null) {

						if (ppData.code == "0") {
							layer.open({
								time: 1000,
								btn: [],
								content: "修改成功!",
							});

							_this.refresh();
							$("#piciModal").modal('hide');

						} else {
							layer.alert(ppData.msg);
						}
					}
				}, "json");
			}
		},

		Delete:function(ppId){
			var _this = this;


			if (confirm("确定要删除吗？")) {
				var pici_layer = layer.open({type:3});
				$.post('/system/qushiquerenpici/delete', {
					id: ppId,
					rdm: Math.random()
				}, function (ppData) {
					layer.close(pici_layer);

					if (ppData != null) {

						if (ppData.code == "0") {
							layer.open({
								time: 1000,
								btn: [],
								content: "删除成功!",
							});

							_this.refresh();
						} else {
							layer.alert(ppData.msg);
						}
					}
				}, "json");
			}
		},

		//检查项目数据
		checkInputData : function() {
			if (!$.trim(this.pici.picimingcheng)) {
				layer.alert("请人口库核查批次名称！");
				return false;
			}

			return true;
		},

		getDate_chaxun:function(){
			var _this = this;

			_this.chuangjianshijian=$("#chuangjianshijian_chaxun").val();
		},

		refresh:function(){
			var _this = this;

			this.picimingcheng=""
			this.chuangjianshijian=""
			// 刷新页面
			_this.bindPiciList();
		},

		toManage : function(piciitem){
			$.modal.openTab(piciitem.picimingcheng+"详情",'/system/zhuanjiaqushiqueren/qushiquerenmanage?piciid='+piciitem.id,false);
		},

		//首页
		firstPage : function(){
			this.pageindex = 1;
		},
		//尾页
		lastPage : function(){
			this.pageindex = this.pageCount;
		},
		//上一页
		prePage : function(){
			var prePage = ((this.pageindex -1) <= 0) ? 1 : (this.pageindex -1);
			this.pageindex = prePage;
		},
		//下一页
		nextPage : function(){
			var nextPage = ((this.pageindex +1) >= this.pageCount) ? this.pageCount : (this.pageindex +1);
			this.pageindex = nextPage;
		},
		//跳到目标页
		targetPage : function() {
			if( this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0){
				this.pageindex = this.targetpage;
				this.targetpage = '';
			}
		},

	},
})